﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Handrise.CDCable.Mobile.Business
{
    /// <summary>
    /// 标准数据服务，设备类型、缺陷类型等数据的操作
    /// </summary>
    public class StandardDataService
    {
        /// <summary>
        /// 更新标准数据
        /// </summary>
        /// <param name="standardDatas"></param>
        /// <returns></returns>
        public bool UpdateStandardData(List<Object> standardDatas,string type)
        {
            try
            {
                //先清除之前的数据（由于不是增量数据，所有每次清除，保证不更新，只插入）
                DeleteStandardData(type);

                foreach (Object standardData in standardDatas)
                {
                    switch (type)
                    {
                        case "MtdEqptype": //设备类型
                            if (AppLogic.dataService.Add<EquipmentType>((EquipmentType)standardData) != 1)
                                AppLogic.dataService.Update<EquipmentType>((EquipmentType)standardData);
                            break;
                        case "MtdSmStdFlawphenomenonData": //缺陷类型
                            if (AppLogic.dataService.Add<FlawPhenomenon>((FlawPhenomenon)standardData) != 1)
                                AppLogic.dataService.Update<FlawPhenomenon>((FlawPhenomenon)standardData);
                            break;
                        case "MtdSmStdPatrolstypeData": //巡视要点
                            if (AppLogic.dataService.Add<PatrolItem>((PatrolItem)standardData) != 1)
                                AppLogic.dataService.Update<PatrolItem>((PatrolItem)standardData);
                            break;
                        case "MtdSmSystemdicData": //系统字典
                            if (AppLogic.dataService.Add<SystemDic>((SystemDic)standardData) != 1)
                                AppLogic.dataService.Update<SystemDic>((SystemDic)standardData);
                            break;
                        case "MtdSmSystemdicTypeData": //系统字典类型
                            if (AppLogic.dataService.Add<SystemDicType>((SystemDicType)standardData) != 1)
                                AppLogic.dataService.Update<SystemDicType>((SystemDicType)standardData);
                            break;
                        case "MtdEmAlltunwellrel": //隧道与井关系
                            if (AppLogic.dataService.Add<TunnelWellRel>((TunnelWellRel)standardData) != 1)
                                AppLogic.dataService.Update<TunnelWellRel>((TunnelWellRel)standardData);
                            break;
                        case "MtdEmCabletunnelrel": //电缆段与隧道关系
                            if (AppLogic.dataService.Add<CableTunnelRel>((CableTunnelRel)standardData) != 1)
                                AppLogic.dataService.Update<CableTunnelRel>((CableTunnelRel)standardData);
                            break;
                        case "MtdEmPassageway": //线路通道路径
                            if (AppLogic.dataService.Add<Passageway>((Passageway)standardData) != 1)
                                AppLogic.dataService.Update<Passageway>((Passageway)standardData);
                            break;

                            
                        default:
                            break;
                    }
                }
                return true;  
            }
            catch (Exception)
            {
                
                return false ;
            }
             


        }

        private void DeleteStandardData(string type)
        {
            switch (type)
            {
                case "MtdEqptype": //设备类型
                    AppLogic.dataService.ExecuteSql("Delete From EquipmentType");
                    break;
                case "MtdSmStdFlawphenomenonData": //缺陷类型
                    AppLogic.dataService.ExecuteSql("Delete From FlawPhenomenon");
                    break;
                case "MtdSmStdPatrolstypeData": //巡视要点
                    AppLogic.dataService.ExecuteSql("Delete From PatrolItem");
                    break;
                case "MtdSmSystemdicData": //系统字典
                    AppLogic.dataService.ExecuteSql("Delete From SystemDic");
                    break;
                case "MtdSmSystemdicTypeData": //系统字典类型
                    AppLogic.dataService.ExecuteSql("Delete From SystemDicType");
                    break;
                case "MtdEmAlltunwellrel": //隧道与井关系
                    AppLogic.dataService.ExecuteSql("Delete From TunnelWellRel");
                    break;
                case "MtdEmCabletunnelrel": //电缆段与隧道关系
                    AppLogic.dataService.ExecuteSql("Delete From CableTunnelRel");
                    break;
                case "MtdEmPassageway": //线路通道路径
                    AppLogic.dataService.ExecuteSql("Delete From Passageway");
                    break;


                default:
                    break;
            }
        }
    }
}
